#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,tot[21],o[21][800005],sz[800005],f[21][800005],rt[21][800005],ans;
struct ok{
	int x,y,z;
}a[800005];
struct node{
	int d,z,id;
};
vector<node> e[800005];
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
inline void write(int x){
	int tnt=0;char f[20];
	if(x<0) x=-x,putchar('-');
	if(!x) {putchar('0');return;}
	while(x) f[++tnt]=x%10,x/=10;
	while(tnt) putchar(f[tnt--]+'0'); 
}
void dfs(int k,int fa,int g){
	sz[k]=1;
	int SZ=e[k].size();
	for(int i=0;i<SZ;i++){
		int v=e[k][i].d,Z=e[k][i].z;
		if(v==fa) continue;
		if(Z>=g){
			f[g][v]=f[g][k];
			rt[g][f[g][k]]++;
		}
		dfs(v,k,g);
		o[g][e[k][i].id]=sz[v];
		if(Z>=g) sz[k]+=sz[v];
	}
}
signed main(){
	freopen("tatooine.in","r",stdin);
	freopen("tatooine.out","w",stdout);
	n=read();
	for(int i=1;i<n;i++){
		a[i].x=read(),a[i].y=read(),a[i].z=read();
		e[a[i].x].push_back((node){a[i].y,a[i].z,i});
		e[a[i].y].push_back((node){a[i].x,a[i].z,i});
	}
	for(int i=1;i<=20;++i){
		for(int j=1;j<=n;++j) f[i][j]=j,rt[i][j]=1,sz[j]=0;
		dfs(1,0,i);
		for(int j=1;j<=n;++j){
			if(j==f[i][j]&&rt[i][j]>1) tot[i]=tot[i]+(rt[i][j]*(rt[i][j]-(int)1)/(int)2);
		}
	} 
	for(int i=1;i<n;i++){
		ans=0;
		for(int j=1;j<=20;j++){
			if(f[j][a[i].x]==f[j][a[i].y]){
				int s=f[j][a[i].x];
				int D=rt[j][s]*(rt[j][s]-(int)1)/(int)2;
				ans+=tot[j];
				ans-=D;
				int E=rt[j][s]-o[j][i];
				ans=ans+(E*(E-(int)1)/(int)2);
				E=o[j][i];
				ans=ans+(E*(E-(int)1)/(int)2);
			}
			else ans+=tot[j];
		}
		write(ans);
		putchar('\n');
	}
	return 0;
}
